using Tycho.Parser.Tokens;

namespace Tycho.Parser.Peg {
    public class LiteralRule<Context> : Rule<Context> {
        private readonly Production<Context> Production;

        public LiteralRule (Production<Context> production) {
            Production = production;
        }

        protected override RuleParseResult<Context> ReallyParse (Token[] tokens, int index, Context context) {
            ParseResult<Context> result = Production.Parse (tokens, index, context);

            if (result != null) {
                return new RuleParseResult<Context> (result.Index, result.Context);
            } else {
                return null;
            }
        }
    }
}